package com.ws.universal.tools.loading.button;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.DashPathEffect;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.graphics.PathMeasure;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.DecelerateInterpolator;

import com.ws.universal.tools.R;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import kotlin.Unit;
import kotlin.jvm.JvmOverloads;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.Intrinsics;


public class LoadingButton extends View {
    @NotNull
    public static final LoadingButton.Companion Companion = new LoadingButton.Companion((DefaultConstructorMarker) null);
    private static final int STATE_BUTTON = 0;
    private static final int STATE_ANIMATION_STEP1 = 1;
    private static final int STATE_ANIMATION_STEP2 = 2;
    private static final int STATE_ANIMATION_LOADING = 3;
    private static final int STATE_STOP_LOADING = 4;
    private static final int STATE_ANIMATION_SUCCESS = 5;
    private static final int STATE_ANIMATION_FAILED = 6;
    private static final int DEFAULT_WIDTH = 88;
    private static final int DEFAULT_HEIGHT = 56;
    private static final int DEFAULT_COLOR = -16776961;
    private static final int DEFAULT_TEXT_COLOR = -1;
    private float mDensity;
    private float defaultMinHeight;
    @Nullable
    private Function1 animationEndAction;
    private boolean rippleEnable;
    private int rippleColor;
    private boolean resetAfterFailed;
    private int mCurrentState;
    private float mMinHeight;
    private int mColorPrimary;
    private int mDisabledBgColor;
    private int mTextColor;
    private int mDisabledTextColor;
    private float mRippleAlpha;
    private float mPadding;
    private Paint mPaint;
    private Paint mRipplePaint;
    private Paint mStrokePaint;
    private Paint mTextPaint;
    private Paint mPathEffectPaint;
    private Paint mPathEffectPaint2;
    private int mScaleWidth;
    private int mScaleHeight;
    private int mDegree;
    private int mAngle;
    private int mEndAngle;
    private float mButtonCorner;
    private int mRadius;
    private float mTextWidth;
    private float mTextHeight;
    private Matrix mMatrix;
    private Path mPath;
    private Path mSuccessPath;
    private float mSuccessPathLength;
    private float[] mSuccessPathIntervals;
    private Path mFailedPath;
    private Path mFailedPath2;
    private float mFailedPathLength;
    private float[] mFailedPathIntervals;
    private float mTouchX;
    private float mTouchY;
    private float mRippleRadius;
    private RectF mButtonRectF;
    private RectF mArcRectF;
    private String mText;
    private AnimatorSet mLoadingAnimatorSet;

    @JvmOverloads
    public LoadingButton(@NotNull Context context) {
        this(context, null);
    }

    @JvmOverloads
    public LoadingButton(@NotNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    @SuppressLint("WrongConstant")
    @JvmOverloads
    public LoadingButton(@NotNull Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        Intrinsics.checkParameterIsNotNull(context, "context");
        Resources var10001 = this.getResources();
        Intrinsics.checkExpressionValueIsNotNull(var10001, "resources");
        this.mDensity = var10001.getDisplayMetrics().density;
        this.defaultMinHeight = (float) 48 * this.mDensity;
        this.rippleEnable = true;
        this.rippleColor = -16777216;
        this.resetAfterFailed = true;
        this.mMinHeight = this.defaultMinHeight;
        this.mColorPrimary = -16776961;
        this.mDisabledBgColor = -3355444;
        this.mTextColor = -1;
        this.mDisabledTextColor = -12303292;
        this.mRippleAlpha = 0.2F;
        this.mPadding = (float) 6 * this.mDensity;
        this.mPaint = new Paint();
        this.mRipplePaint = new Paint();
        this.mStrokePaint = new Paint();
        this.mTextPaint = new Paint();
        this.mPathEffectPaint = new Paint();
        this.mPathEffectPaint2 = new Paint();
        this.mButtonCorner = (float) 2 * this.mDensity;
        this.mMatrix = new Matrix();
        this.mPath = new Path();
        this.mButtonRectF = new RectF();
        this.mArcRectF = new RectF();
        this.mText = "";
        if (attrs != null) {
            TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.LoadingButton, 0, 0);
            this.mColorPrimary = ta.getInt(R.styleable.LoadingButton_lb_btnColor, -16776961);
            this.mDisabledBgColor = ta.getColor(R.styleable.LoadingButton_lb_btnDisabledColor, -3355444);
            this.mDisabledTextColor = ta.getColor(R.styleable.LoadingButton_lb_disabledTextColor, -12303292);
            String text = ta.getString(R.styleable.LoadingButton_lb_btnText);
            String var11 = text;
            if (text == null) {
                var11 = "";
            }

            this.mText = var11;
            this.mTextColor = ta.getColor(R.styleable.LoadingButton_lb_textColor, -1);
            this.resetAfterFailed = ta.getBoolean(R.styleable.LoadingButton_lb_resetAfterFailed, true);
            this.setRippleColor(ta.getColor(R.styleable.LoadingButton_lb_btnRippleColor, -16777216));
            this.setRippleEnable(ta.getBoolean(R.styleable.LoadingButton_lb_rippleEnable, true));
            this.mRippleAlpha = ta.getFloat(R.styleable.LoadingButton_lb_btnRippleAlpha, 0.3F);
            this.mButtonCorner = ta.getDimension(R.styleable.LoadingButton_lb_cornerRadius, (float) 2 * this.mDensity);
            this.mMinHeight = ta.getDimension(R.styleable.LoadingButton_lb_min_height, this.defaultMinHeight);
            ta.recycle();
        }

        Paint var9 = this.mPaint;
        boolean var10 = false;
        boolean var6 = false;
        boolean var8 = false;
        this.setLayerType(1, var9);
        var9.setAntiAlias(true);
        var9.setColor(this.mColorPrimary);
        var9.setStyle(Paint.Style.FILL);
        LoadingButtonKt.access$setShadowDepth(var9, (float) 2 * this.mDensity);
        var9 = this.mRipplePaint;
        var10 = false;
        var6 = false;
        var8 = false;
        var9.setAntiAlias(true);
        var9.setColor(this.rippleColor);
        var9.setAlpha((int) (this.mRippleAlpha * (float) 255));
        var9.setStyle(Paint.Style.FILL);
        var9 = this.mStrokePaint;
        var10 = false;
        var6 = false;
        var8 = false;
        var9.setAntiAlias(true);
        var9.setColor(this.mColorPrimary);
        var9.setStyle(Paint.Style.STROKE);
        var9.setStrokeWidth((float) 2 * this.mDensity);
        var9 = this.mTextPaint;
        var10 = false;
        var6 = false;
        var8 = false;
        var9.setAntiAlias(true);
        var9.setColor(this.mTextColor);
        var9.setTextSize((float) 16 * this.mDensity);
        var9.setFakeBoldText(true);
        this.mTextWidth = this.mTextPaint.measureText(this.mText);
        this.mTextHeight = this.measureTextHeight(this.mTextPaint);
        var9 = this.mPathEffectPaint;
        var10 = false;
        var6 = false;
        var8 = false;
        var9.setAntiAlias(true);
        var9.setColor(this.mColorPrimary);
        var9.setStyle(Paint.Style.STROKE);
        var9.setStrokeWidth((float) 2 * this.mDensity);
        var9 = this.mPathEffectPaint2;
        var10 = false;
        var6 = false;
        var8 = false;
        var9.setAntiAlias(true);
        var9.setColor(this.mColorPrimary);
        var9.setStyle(Paint.Style.STROKE);
        var9.setStrokeWidth((float) 2 * this.mDensity);
        this.setLayerType(View.LAYER_TYPE_SOFTWARE, this.mPaint);


    }

    // $FF: synthetic method
    public static final Paint access$getMPaint$p(LoadingButton $this) {
        return $this.mPaint;
    }

    // $FF: synthetic method
    public static final float access$getMDensity$p(LoadingButton $this) {
        return $this.mDensity;
    }

    // $FF: synthetic method
    public static final float access$getMRippleRadius$p(LoadingButton $this) {
        return $this.mRippleRadius;
    }

    // $FF: synthetic method
    public static final void access$setMRippleRadius$p(LoadingButton $this, float var1) {
        $this.mRippleRadius = var1;
    }

    // $FF: synthetic method
    public static final Paint access$getMRipplePaint$p(LoadingButton $this) {
        return $this.mRipplePaint;
    }

    // $FF: synthetic method
    public static final float access$getMRippleAlpha$p(LoadingButton $this) {
        return $this.mRippleAlpha;
    }

    // $FF: synthetic method
    public static final void access$setMRippleAlpha$p(LoadingButton $this, float var1) {
        $this.mRippleAlpha = var1;
    }

    // $FF: synthetic method
    public static final void access$doClick(LoadingButton $this) {
        $this.doClick();
    }

    // $FF: synthetic method
    public static final int access$getMScaleWidth$p(LoadingButton $this) {
        return $this.mScaleWidth;
    }

    // $FF: synthetic method
    public static final void access$setMScaleWidth$p(LoadingButton $this, int var1) {
        $this.mScaleWidth = var1;
    }

    // $FF: synthetic method
    public static final int access$getMCurrentState$p(LoadingButton $this) {
        return $this.mCurrentState;
    }

    // $FF: synthetic method
    public static final void access$setMCurrentState$p(LoadingButton $this, int var1) {
        $this.mCurrentState = var1;
    }

    // $FF: synthetic method
    public static final int access$getMScaleHeight$p(LoadingButton $this) {
        return $this.mScaleHeight;
    }

    // $FF: synthetic method
    public static final void access$setMScaleHeight$p(LoadingButton $this, int var1) {
        $this.mScaleHeight = var1;
    }

    // $FF: synthetic method
    public static final int access$getMAngle$p(LoadingButton $this) {
        return $this.mAngle;
    }

    // $FF: synthetic method
    public static final void access$setMAngle$p(LoadingButton $this, int var1) {
        $this.mAngle = var1;
    }

    // $FF: synthetic method
    public static final int access$getMEndAngle$p(LoadingButton $this) {
        return $this.mEndAngle;
    }

    // $FF: synthetic method
    public static final void access$setMEndAngle$p(LoadingButton $this, int var1) {
        $this.mEndAngle = var1;
    }

    // $FF: synthetic method
    public static final float[] access$getMSuccessPathIntervals$p(LoadingButton $this) {
        return $this.mSuccessPathIntervals;
    }

    // $FF: synthetic method
    public static final void access$setMSuccessPathIntervals$p(LoadingButton $this, float[] var1) {
        $this.mSuccessPathIntervals = var1;
    }

    // $FF: synthetic method
    public static final float access$getMSuccessPathLength$p(LoadingButton $this) {
        return $this.mSuccessPathLength;
    }

    // $FF: synthetic method
    public static final void access$setMSuccessPathLength$p(LoadingButton $this, float var1) {
        $this.mSuccessPathLength = var1;
    }

    // $FF: synthetic method
    public static final Paint access$getMPathEffectPaint$p(LoadingButton $this) {
        return $this.mPathEffectPaint;
    }

    // $FF: synthetic method
    public static final float[] access$getMFailedPathIntervals$p(LoadingButton $this) {
        return $this.mFailedPathIntervals;
    }

    // $FF: synthetic method
    public static final void access$setMFailedPathIntervals$p(LoadingButton $this, float[] var1) {
        $this.mFailedPathIntervals = var1;
    }

    // $FF: synthetic method
    public static final float access$getMFailedPathLength$p(LoadingButton $this) {
        return $this.mFailedPathLength;
    }

    // $FF: synthetic method
    public static final void access$setMFailedPathLength$p(LoadingButton $this, float var1) {
        $this.mFailedPathLength = var1;
    }

    // $FF: synthetic method
    public static final Paint access$getMPathEffectPaint2$p(LoadingButton $this) {
        return $this.mPathEffectPaint2;
    }

    // $FF: synthetic method
    public static final void access$scaleFailedPath(LoadingButton $this) {
        $this.scaleFailedPath();
    }

    // $FF: synthetic method
    public static final void access$playStartAnimation(LoadingButton $this, boolean isReverse) {
        $this.playStartAnimation(isReverse);
    }

    // $FF: synthetic method
    public static final Path access$getMSuccessPath$p(LoadingButton $this) {
        return $this.mSuccessPath;
    }

    // $FF: synthetic method
    public static final void access$setMSuccessPath$p(LoadingButton $this, Path var1) {
        $this.mSuccessPath = var1;
    }

    // $FF: synthetic method
    public static final Path access$getMFailedPath$p(LoadingButton $this) {
        return $this.mFailedPath;
    }

    // $FF: synthetic method
    public static final void access$setMFailedPath$p(LoadingButton $this, Path var1) {
        $this.mFailedPath = var1;
    }

    // $FF: synthetic method
    public static final Path access$getMFailedPath2$p(LoadingButton $this) {
        return $this.mFailedPath2;
    }

    // $FF: synthetic method
    public static final void access$setMFailedPath2$p(LoadingButton $this, Path var1) {
        $this.mFailedPath2 = var1;
    }

    @Nullable
    public final Function1 getAnimationEndAction() {
        return this.animationEndAction;
    }

    public final void setAnimationEndAction(@Nullable Function1 var1) {
        this.animationEndAction = var1;
    }

    public final boolean getRippleEnable() {
        return this.rippleEnable;
    }

    public final void setRippleEnable(boolean value) {
        this.invalidate();
        this.rippleEnable = value;
    }

    public final int getRippleColor() {
        return this.rippleColor;
    }

    public final void setRippleColor(int value) {
        this.mRipplePaint.setColor(value);
        this.rippleColor = value;
    }

    public final int getTextColor() {
        return this.mTextColor;
    }

    public final void setTextColor(int value) {
        this.mTextColor = value;
        this.invalidate();
    }

    @NotNull
    public final Typeface getTypeface() {
        Typeface var10000 = this.mTextPaint.getTypeface();
        Intrinsics.checkExpressionValueIsNotNull(var10000, "mTextPaint.typeface");
        return var10000;
    }

    public final void setTypeface(@NotNull Typeface value) {
        Intrinsics.checkParameterIsNotNull(value, "value");
        this.mTextPaint.setTypeface(value);
        this.invalidate();
    }

    @NotNull
    public final String getText() {
        return this.mText;
    }

    public final void setText(@NotNull String value) {
        Intrinsics.checkParameterIsNotNull(value, "value");
        CharSequence var2 = (CharSequence) this.getText();
        boolean var3 = false;
        if (var2.length() != 0) {
            this.mText = value;
            this.mTextWidth = this.mTextPaint.measureText(this.mText);
            this.mTextHeight = this.measureTextHeight(this.mTextPaint);
            this.invalidate();
        }
    }

    public final int getTextSize() {
        return (int) (this.mTextPaint.getTextSize() / this.mDensity);
    }

    public final void setTextSize(int value) {
        this.mTextPaint.setTextSize((float) value * this.mDensity);
        this.mTextWidth = this.mTextPaint.measureText(this.mText);
        this.invalidate();
    }

    public final float getCornerRadius() {
        return this.mButtonCorner;
    }

    public final void setCornerRadius(float value) {
        this.mButtonCorner = value;
        this.invalidate();
    }

    public final boolean getResetAfterFailed() {
        return this.resetAfterFailed;
    }

    public final void setResetAfterFailed(boolean var1) {
        this.resetAfterFailed = var1;
    }

    @Nullable
    public final Shader getBackgroundShader() {
        return this.mStrokePaint.getShader();
    }

    public final void setBackgroundShader(@Nullable Shader value) {
        this.mPaint.setShader(value);
        this.mStrokePaint.setShader(value);
        this.mPathEffectPaint.setShader(value);
        this.mPathEffectPaint2.setShader(value);
        this.invalidate();
    }

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        this.setMeasuredDimension(this.measureDimension((int) ((float) 88 * this.mDensity), widthMeasureSpec), this.measureDimension((int) ((float) 56 * this.mDensity), heightMeasureSpec));
    }

    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        int var6 = (int) this.mMinHeight;
        boolean var7 = false;
        int viewHeight = Math.max(h, var6);
        this.mRadius = (int) ((float) viewHeight - this.mPadding * (float) 2) / 2;
        this.mButtonRectF.top = this.mPadding;
        this.mButtonRectF.bottom = (float) viewHeight - this.mPadding;
        this.mArcRectF.left = (float) (this.getWidth() / 2 - this.mRadius);
        this.mArcRectF.top = this.mPadding;
        this.mArcRectF.right = (float) (this.getWidth() / 2 + this.mRadius);
        this.mArcRectF.bottom = (float) viewHeight - this.mPadding;
    }

    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        if (this.mCurrentState == 0) {
            this.updateButtonColor();
        }

    }

    @SuppressLint({"ClickableViewAccessibility"})
    public boolean onTouchEvent(@NotNull MotionEvent event) {
        Intrinsics.checkParameterIsNotNull(event, "event");
        if (!this.isEnabled()) {
            return true;
        } else {
            switch (event.getAction()) {
                case 0:
                    this.mTouchX = event.getX();
                    this.mTouchY = event.getY();
                    this.playTouchDownAnimation();
                    break;
                case 1:
                    if (event.getX() > this.mButtonRectF.left && event.getX() < this.mButtonRectF.right && event.getY() > this.mButtonRectF.top && event.getY() < this.mButtonRectF.bottom) {
                        this.playRippleAnimation();
                    } else {
                        this.mTouchX = 0.0F;
                        this.mTouchY = 0.0F;
                        this.mRippleRadius = 0.0F;
                        this.mRipplePaint.setAlpha((int) (this.mRippleAlpha * (float) 255));
                        LoadingButtonKt.access$setShadowDepth(this.mPaint, (float) 2 * this.mDensity);
                        this.invalidate();
                    }
            }

            return true;
        }
    }

    protected void onDraw(@NotNull Canvas canvas) {
        Intrinsics.checkParameterIsNotNull(canvas, "canvas");
        super.onDraw(canvas);
        int var3 = this.getHeight();
        int var4 = (int) this.mMinHeight;
        boolean var5 = false;
        int viewHeight = Math.max(var3, var4);
        Path var10001;
        switch (this.mCurrentState) {
            case 0:
            case 1:
                float cornerRadius = ((float) this.mRadius - this.mButtonCorner) * ((float) this.mScaleWidth / (float) (this.getWidth() / 2 - viewHeight / 2)) + this.mButtonCorner;
                this.mButtonRectF.left = (float) this.mScaleWidth;
                this.mButtonRectF.right = (float) (this.getWidth() - this.mScaleWidth);
                canvas.drawRoundRect(this.mButtonRectF, cornerRadius, cornerRadius, this.mPaint);
                if (this.mCurrentState == 0) {
                    canvas.drawText(this.mText, ((float) this.getWidth() - this.mTextWidth) / (float) 2, ((float) viewHeight - this.mTextHeight) / (float) 2 + this.mPadding * (float) 2, this.mTextPaint);
                    if ((this.mTouchX > (float) 0 || this.mTouchY > (float) 0) && this.rippleEnable) {
                        canvas.clipRect(0.0F, this.mPadding, (float) this.getWidth(), (float) viewHeight - this.mPadding);
                        canvas.drawCircle(this.mTouchX, this.mTouchY, this.mRippleRadius, this.mRipplePaint);
                    }
                }
                break;
            case 2:
                canvas.drawCircle((float) (this.getWidth() / 2), (float) (viewHeight / 2), (float) (this.mRadius - this.mScaleHeight), this.mPaint);
                canvas.drawCircle((float) (this.getWidth() / 2), (float) (viewHeight / 2), (float) this.mRadius - this.mDensity, this.mStrokePaint);
                break;
            case 3:
                this.mPath.reset();
                this.mPath.addArc(this.mArcRectF, (float) (270 + this.mAngle / 2), (float) (360 - this.mAngle));
                if (this.mAngle != 0) {
                    this.mMatrix.setRotate((float) this.mDegree, (float) (this.getWidth() / 2), (float) (viewHeight / 2));
                    this.mPath.transform(this.mMatrix);
                    this.mDegree += 10;
                }

                canvas.drawPath(this.mPath, this.mStrokePaint);
                break;
            case 4:
                this.mPath.reset();
                this.mPath.addArc(this.mArcRectF, (float) (270 + this.mAngle / 2), (float) this.mEndAngle);
                if (this.mEndAngle != 360) {
                    this.mMatrix.setRotate((float) this.mDegree, (float) (this.getWidth() / 2), (float) (viewHeight / 2));
                    this.mPath.transform(this.mMatrix);
                    this.mDegree += 10;
                }

                canvas.drawPath(this.mPath, this.mStrokePaint);
                break;
            case 5:
                var10001 = this.mSuccessPath;
                if (var10001 == null) {
                    Intrinsics.throwNpe();
                }

                canvas.drawPath(var10001, this.mPathEffectPaint);
                canvas.drawCircle((float) (this.getWidth() / 2), (float) (viewHeight / 2), (float) this.mRadius - this.mDensity, this.mStrokePaint);
                break;
            case 6:
                var10001 = this.mFailedPath;
                if (var10001 == null) {
                    Intrinsics.throwNpe();
                }

                canvas.drawPath(var10001, this.mPathEffectPaint);
                var10001 = this.mFailedPath2;
                if (var10001 == null) {
                    Intrinsics.throwNpe();
                }

                canvas.drawPath(var10001, this.mPathEffectPaint2);
                canvas.drawCircle((float) (this.getWidth() / 2), (float) (viewHeight / 2), (float) this.mRadius - this.mDensity, this.mStrokePaint);
        }

    }

    public final void startLoading() {
        if (this.mCurrentState == 6 && !this.resetAfterFailed) {
            this.scaleFailedPath();
        } else {
            if (this.mCurrentState == 0) {
                this.mCurrentState = 1;
                this.mPaint.clearShadowLayer();
                this.playStartAnimation(false);
            }

        }
    }

    public final void loadingSuccessful() {
        if (this.mLoadingAnimatorSet != null) {
            AnimatorSet var10000 = this.mLoadingAnimatorSet;
            if (var10000 == null) {
                Intrinsics.throwNpe();
            }

            if (var10000.isStarted()) {
                var10000 = this.mLoadingAnimatorSet;
                if (var10000 == null) {
                    Intrinsics.throwNpe();
                }

                var10000.end();
                this.mCurrentState = 4;
                this.playSuccessAnimation();
            }
        }

    }

    public final void loadingFailed() {
        if (this.mLoadingAnimatorSet != null) {
            AnimatorSet var10000 = this.mLoadingAnimatorSet;
            if (var10000 == null) {
                Intrinsics.throwNpe();
            }

            if (var10000.isStarted()) {
                var10000 = this.mLoadingAnimatorSet;
                if (var10000 == null) {
                    Intrinsics.throwNpe();
                }

                var10000.end();
                this.mCurrentState = 4;
                this.playFailedAnimation();
            }
        }

    }

    public final void cancelLoading() {
        if (this.mCurrentState == 3) {
            this.cancel();
        }
    }

    public final void reset() {
        switch (this.mCurrentState) {
            case 5:
                this.scaleSuccessPath();
                break;
            case 6:
                this.scaleFailedPath();
        }

    }

    private final float measureTextHeight(Paint paint) {
        Rect bounds = new Rect();
        paint.getTextBounds(this.mText, 0, this.mText.length(), bounds);
        return (float) bounds.height();
    }

    private final void createSuccessPath() {
        if (this.mSuccessPath != null) {
            Path var10000 = this.mSuccessPath;
            if (var10000 == null) {
                Intrinsics.throwNpe();
            }

            var10000.reset();
        } else {
            this.mSuccessPath = new Path();
        }

        float mLineWith = (float) 2 * this.mDensity;
        float left = (float) (this.getWidth() / 2 - this.mRadius) + (float) (this.mRadius / 3) + mLineWith;
        float top = this.mPadding + (float) (this.mRadius / 2) + mLineWith;
        float right = (float) (this.getWidth() / 2 + this.mRadius) - mLineWith - (float) (this.mRadius / 3);
        float bottom = (mLineWith + (float) this.mRadius) * 1.5F + this.mPadding / (float) 2;
        float xPoint = (float) (this.getWidth() / 2 - this.mRadius / 6);
        Path var7 = new Path();

        var7.moveTo(left, this.mPadding + (float) this.mRadius + mLineWith);
        var7.lineTo(xPoint, bottom);
        var7.lineTo(right, top);
        this.mSuccessPath = var7;
        this.mSuccessPathLength = (new PathMeasure(this.mSuccessPath, false)).getLength();
        this.mSuccessPathIntervals = new float[]{this.mSuccessPathLength, this.mSuccessPathLength};
    }

    private final void createFailedPath() {
        Path var10000;
        if (this.mFailedPath != null) {
            var10000 = this.mFailedPath;
            if (var10000 == null) {
                Intrinsics.throwNpe();
            }

            var10000.reset();
            var10000 = this.mFailedPath2;
            if (var10000 == null) {
                Intrinsics.throwNpe();
            }

            var10000.reset();
        } else {
            this.mFailedPath = new Path();
            this.mFailedPath2 = new Path();
        }

        float left = (float) (this.getWidth() / 2 - this.mRadius + this.mRadius / 2);
        float top = (float) (this.mRadius / 2) + this.mPadding;
        var10000 = this.mFailedPath;
        if (var10000 == null) {
            Intrinsics.throwNpe();
        }

        var10000.moveTo(left, top);
        var10000 = this.mFailedPath;
        if (var10000 == null) {
            Intrinsics.throwNpe();
        }

        var10000.lineTo(left + (float) this.mRadius, top + (float) this.mRadius);
        var10000 = this.mFailedPath2;
        if (var10000 == null) {
            Intrinsics.throwNpe();
        }

        var10000.moveTo((float) (this.getWidth() / 2 + this.mRadius / 2), top);
        var10000 = this.mFailedPath2;
        if (var10000 == null) {
            Intrinsics.throwNpe();
        }

        var10000.lineTo((float) (this.getWidth() / 2 - this.mRadius + this.mRadius / 2), top + (float) this.mRadius);
        this.mFailedPathLength = (new PathMeasure(this.mFailedPath, false)).getLength();
        this.mFailedPathIntervals = new float[]{this.mFailedPathLength, this.mFailedPathLength};
        this.mPathEffectPaint2.setPathEffect((PathEffect) (new DashPathEffect(this.mFailedPathIntervals, this.mFailedPathLength)));
    }

    private final int measureDimension(int defaultSize, int measureSpec) {
        int var10000;
        switch (MeasureSpec.getMode(measureSpec)) {
            case Integer.MIN_VALUE:
                int var3 = MeasureSpec.getSize(measureSpec);
                boolean var4 = false;
                var10000 = Math.min(defaultSize, var3);
                break;
            case 0:
                var10000 = defaultSize;
                break;
            case 1073741824:
                var10000 = MeasureSpec.getSize(measureSpec);
                break;
            default:
                var10000 = defaultSize;
        }

        return var10000;
    }

    private final void updateButtonColor() {
        this.mPaint.setColor(this.isEnabled() ? this.mColorPrimary : this.mDisabledBgColor);
        this.mTextPaint.setColor(this.isEnabled() ? this.mTextColor : this.mDisabledTextColor);
        if (this.getBackgroundShader() != null) {
            if (this.isEnabled()) {
                this.mPaint.setShader(this.getBackgroundShader());
            } else {
                this.mPaint.setShader((Shader) null);
            }
        }

        this.invalidate();
    }

    private final void playTouchDownAnimation() {
        ValueAnimator var1 = ValueAnimator.ofFloat(new float[]{0.0F, 1.0F});
        var1.setDuration(240L);
        var1.setInterpolator((TimeInterpolator) (new AccelerateDecelerateInterpolator()));
        var1.addUpdateListener((ValueAnimator.AnimatorUpdateListener) (new LoadingButton$playTouchDownAnimation$$inlined$apply$lambda$1(this)));
        var1.start();
    }

    private final void playRippleAnimation() {
        ValueAnimator var1 = ValueAnimator.ofFloat(new float[]{1.0F, 0.0F});
        var1.setDuration(240L);
        var1.setInterpolator((TimeInterpolator) (new DecelerateInterpolator()));
        var1.addUpdateListener((ValueAnimator.AnimatorUpdateListener) (new LoadingButton$playRippleAnimation$$inlined$apply$lambda$1(this)));
        LoadingButtonKt.access$doOnEnd((Animator) var1, (Function1) (new LoadingButton$playRippleAnimation$$inlined$apply$lambda$2(this)));
        var1.start();
    }

    private final void doClick() {
        this.mTouchX = 0.0F;
        this.mTouchY = 0.0F;
        this.mRipplePaint.setAlpha((int) (this.mRippleAlpha * (float) 255));
        this.mRippleRadius = 0.0F;
        this.invalidate();
        this.performClick();
    }

    @SuppressLint("WrongConstant")
    private final void playStartAnimation(boolean isReverse) {
        int var3 = this.getHeight();
        int var4 = (int) this.mMinHeight;
        int viewHeight = Math.max(var3, var4);
        ValueAnimator var11 = ValueAnimator.ofInt(new int[]{isReverse ? this.getWidth() / 2 - viewHeight / 2 : 0, isReverse ? 0 : this.getWidth() / 2 - viewHeight / 2});
        var11.setDuration(400L);
        var11.setInterpolator(new AccelerateDecelerateInterpolator());
        var11.setStartDelay(100L);
        var11.addUpdateListener(new LoadingButton$playStartAnimation$$inlined$apply$lambda$1(this, isReverse));
        LoadingButtonKt.access$doOnEnd(var11, new LoadingButton$playStartAnimation$$inlined$apply$lambda$2(this, isReverse));
        ValueAnimator var12 = ValueAnimator.ofInt(new int[]{isReverse ? this.mRadius : 0, isReverse ? 0 : this.mRadius});

        var12.setDuration(240L);
        var12.setInterpolator(new AccelerateDecelerateInterpolator());
        var12.addUpdateListener(new LoadingButton$playStartAnimation$$inlined$apply$lambda$3(this, isReverse));
        LoadingButtonKt.access$doOnEnd(var12, new LoadingButton$playStartAnimation$$inlined$apply$lambda$4(this, isReverse));
        ValueAnimator var13 = ValueAnimator.ofInt(new int[]{30, 300});
        var13.setDuration(1000L);
        var13.setRepeatCount(-1);
        var13.setRepeatMode(2);
        var13.setInterpolator(new AccelerateDecelerateInterpolator());
        var13.addUpdateListener(new LoadingButton$playStartAnimation$$inlined$apply$lambda$5(this));
        AnimatorSet var10000 = this.mLoadingAnimatorSet;
        if (var10000 != null) {
            var10000.cancel();
        }

        this.mLoadingAnimatorSet = new AnimatorSet();
        var10000 = this.mLoadingAnimatorSet;
        if (var10000 == null) {
            Intrinsics.throwNpe();
        }

        LoadingButtonKt.access$doOnEnd(var10000, new Function1() {
            // $FF: synthetic method
            // $FF: bridge method
            public Object invoke(Object var1) {
                this.invoke((Animator) var1);
                return Unit.INSTANCE;
            }

            public final void invoke(@Nullable Animator it) {
                LoadingButton.this.setEnabled(true);
                LoadingButton.this.updateButtonColor();
            }
        });
        if (isReverse) {
            var10000 = this.mLoadingAnimatorSet;
            if (var10000 == null) {
                Intrinsics.throwNpe();
            }

            var10000.playSequentially(new Animator[]{(Animator) var12, (Animator) var11});
            var10000 = this.mLoadingAnimatorSet;
            if (var10000 == null) {
                Intrinsics.throwNpe();
            }

            var10000.start();
        } else {
            var10000 = this.mLoadingAnimatorSet;
            if (var10000 == null) {
                Intrinsics.throwNpe();
            }

            var10000.playSequentially(new Animator[]{(Animator) var11, (Animator) var12, (Animator) var13});
            var10000 = this.mLoadingAnimatorSet;
            if (var10000 == null) {
                Intrinsics.throwNpe();
            }

            var10000.start();
        }
    }

    private final void playSuccessAnimation() {
        this.createSuccessPath();
        ValueAnimator successAnimator = ValueAnimator.ofInt(new int[]{360 - this.mAngle, 360});
        successAnimator.setDuration(240L);
        successAnimator.setInterpolator((TimeInterpolator) (new DecelerateInterpolator()));
        successAnimator.addUpdateListener((ValueAnimator.AnimatorUpdateListener) (new LoadingButton$playSuccessAnimation$$inlined$apply$lambda$1(this)));
        LoadingButtonKt.access$doOnEnd((Animator) successAnimator, (Function1) (new LoadingButton$playSuccessAnimation$$inlined$apply$lambda$2(this)));
        ValueAnimator animator = successAnimator;
        ValueAnimator var8 = ValueAnimator.ofFloat(new float[]{0.0F, 1.0F});

        var8.setDuration(500L);
        var8.setInterpolator((TimeInterpolator) (new AccelerateDecelerateInterpolator()));
        var8.addUpdateListener((ValueAnimator.AnimatorUpdateListener) (new LoadingButton$playSuccessAnimation$$inlined$apply$lambda$3(this)));
        successAnimator = var8;
        AnimatorSet var9 = new AnimatorSet();
        var9.playSequentially(new Animator[]{(Animator) animator, (Animator) successAnimator});
        LoadingButtonKt.access$doOnEnd((Animator) var9, (Function1) (new LoadingButton$playSuccessAnimation$$inlined$apply$lambda$4(this, animator, successAnimator)));
        var9.start();
    }

    private final void playFailedAnimation() {
        this.createFailedPath();
        ValueAnimator failedAnimator = ValueAnimator.ofInt(new int[]{360 - this.mAngle, 360});
        failedAnimator.setDuration(240L);
        failedAnimator.setInterpolator((TimeInterpolator) (new DecelerateInterpolator()));
        failedAnimator.addUpdateListener((ValueAnimator.AnimatorUpdateListener) (new LoadingButton$playFailedAnimation$$inlined$apply$lambda$1(this)));
        LoadingButtonKt.access$doOnEnd((Animator) failedAnimator, (Function1) (new LoadingButton$playFailedAnimation$$inlined$apply$lambda$2(this)));
        ValueAnimator animator = failedAnimator;
        ValueAnimator failedAnimator2 = ValueAnimator.ofFloat(new float[]{0.0F, 1.0F});
        failedAnimator2.setDuration(300L);
        failedAnimator2.setInterpolator((TimeInterpolator) (new AccelerateDecelerateInterpolator()));
        failedAnimator2.addUpdateListener((ValueAnimator.AnimatorUpdateListener) (new LoadingButton$playFailedAnimation$$inlined$apply$lambda$3(this)));
        failedAnimator = failedAnimator2;
        ValueAnimator var10 = ValueAnimator.ofFloat(new float[]{0.0F, 1.0F});
        var10.setDuration(300L);
        var10.setInterpolator((TimeInterpolator) (new AccelerateDecelerateInterpolator()));
        var10.addUpdateListener((ValueAnimator.AnimatorUpdateListener) (new LoadingButton$playFailedAnimation$$inlined$apply$lambda$4(this)));
        failedAnimator2 = var10;
        AnimatorSet var11 = new AnimatorSet();
        var11.playSequentially(new Animator[]{(Animator) animator, (Animator) failedAnimator, (Animator) failedAnimator2});
        LoadingButtonKt.access$doOnEnd((Animator) var11, (Function1) (new LoadingButton$playFailedAnimation$$inlined$apply$lambda$5(this, animator, failedAnimator, failedAnimator2)));
        var11.start();
    }

    private final void cancel() {
        this.mCurrentState = 4;
        ValueAnimator var1 = ValueAnimator.ofInt(new int[]{360 - this.mAngle, 360});
        var1.setDuration(240L);
        var1.setInterpolator((TimeInterpolator) (new DecelerateInterpolator()));
        var1.addUpdateListener((ValueAnimator.AnimatorUpdateListener) (new LoadingButton$cancel$$inlined$apply$lambda$1(this)));
        LoadingButtonKt.access$doOnEnd((Animator) var1, (Function1) (new LoadingButton$cancel$$inlined$apply$lambda$2(this)));
        var1.start();
    }

    private final void scaleSuccessPath() {
        Matrix scaleMatrix = new Matrix();
        int var3 = this.getHeight();
        int var4 = (int) this.mMinHeight;
        int viewHeight = Math.max(var3, var4);
        ValueAnimator var8 = ValueAnimator.ofFloat(new float[]{1.0F, 0.0F});
        var8.setDuration(300L);
        var8.setInterpolator((TimeInterpolator) (new AccelerateDecelerateInterpolator()));
        var8.addUpdateListener((ValueAnimator.AnimatorUpdateListener) (new LoadingButton$scaleSuccessPath$$inlined$apply$lambda$1(this, scaleMatrix, viewHeight)));
        LoadingButtonKt.access$doOnEnd((Animator) var8, (Function1) (new LoadingButton$scaleSuccessPath$$inlined$apply$lambda$2(this, scaleMatrix, viewHeight)));
        var8.start();
    }

    private final void scaleFailedPath() {
        Matrix scaleMatrix = new Matrix();
        int var3 = this.getHeight();
        int var4 = (int) this.mMinHeight;
        int viewHeight = Math.max(var3, var4);
        ValueAnimator var8 = ValueAnimator.ofFloat(new float[]{1.0F, 0.0F});
        var8.setDuration(300L);
        var8.setInterpolator((TimeInterpolator) (new AccelerateDecelerateInterpolator()));
        var8.addUpdateListener((ValueAnimator.AnimatorUpdateListener) (new LoadingButton$scaleFailedPath$$inlined$apply$lambda$1(this, scaleMatrix, viewHeight)));
        LoadingButtonKt.access$doOnEnd((Animator) var8, (Function1) (new LoadingButton$scaleFailedPath$$inlined$apply$lambda$2(this, scaleMatrix, viewHeight)));
        var8.start();
    }

    public static final class Companion {
        private Companion() {
        }

        // $FF: synthetic method
        public Companion(DefaultConstructorMarker $constructor_marker) {
            this();
        }
    }
}
